//
//  KDInfoTypeController.m
//  WangJingApp
//
//  Created by 魏强 on 17/10/13.
//  Copyright © 2017年 KDTech. All rights reserved.
//

#import "KDInfoTypeController.h"
#import "KDChildTypeController.h"
#import "KDInfoType.h"
@interface KDInfoTypeController ()<UITableViewDelegate, UITableViewDataSource>
/**  <#Description#> */
@property (nonatomic, weak) UITableView *tableView;
/**  第一层的所有信息类别 */
@property (nonatomic, strong) NSArray *infoArr;

@end

@implementation KDInfoTypeController
#pragma mark - 懒加载区
- (NSArray *)infoArr
{
    if (!_infoArr) {
        NSMutableArray *arr = [NSMutableArray array];
        for (KDInfoType *type in self.infoTypes) {
            if (type.parent_id == 0) {
                [arr addObject:type];
            }
        }
        _infoArr =  arr;
    }
    return _infoArr;
}
#pragma mark - 生命周期区

#pragma mark - 板块布置区
- (void)setUpTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(10  , 10, self.view.width -20, self.view.height - 64 -10) style:UITableViewStylePlain];
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    self.tableView = tableView;
    //    tableView.editing = YES;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}
#pragma mark - 事件点击区

#pragma mark - 网络请求区

#pragma mark - 通知接收区
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BackGroundColor;
    [self setUpTableView];
    // Do any additional setup after loading the view.
}

#pragma mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.infoArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId =@"cellName";
    
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    KDInfoType *source = self.infoArr[indexPath.row];
    cell.textLabel.text = source.info_type_name;
    
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        //    thisCell.accessoryView.hidden = NO;
    KDInfoType *type = self.infoArr[indexPath.row];
    NSMutableArray *arr = [NSMutableArray array];
    for (KDInfoType *model in self.infoTypes) {
        if (model.parent_id == type.ID) {
            [arr addObject:model];
        }
    }
    
    KDChildTypeController *childType = [[KDChildTypeController alloc]init];
    childType.infoArr = arr;
    childType.title = type.info_type_name;
    [self.navigationController pushViewController:childType animated:YES];
    
}


@end
